package com.example.robot;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

public class ChatAdapter extends BaseAdapter {
    private List<ChatBean> chatBeanList;
    private LayoutInflater layoutInflater;
    public ChatAdapter(List<ChatBean> chatBeanList, Context context) {
        this.chatBeanList=chatBeanList;
        layoutInflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return chatBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return chatBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View contentView, ViewGroup viewGroup) {
        if(chatBeanList.get(position).getState()==ChatBean.RECEIVE){
            contentView=layoutInflater.inflate(R.layout.chatting_left_item,null);
        }else{
            contentView=layoutInflater.inflate(R.layout.chatting_right_item,null);
        }
        TextView tv_chat_content=contentView.findViewById(R.id.tv_chat_content);
        tv_chat_content.setText(chatBeanList.get(position).getMessage());
        return contentView;
    }
}
